//
//  MyTabBar.m
//  Fn
//
//  Created by 王展 on 15/9/27.
//  Copyright (c) 2015年 wangzhan. All rights reserved.
//

#import "MyTabBar.h"
#import "BaseView.h"

@interface MyTabBar ()

@property(nonatomic,retain)UIButton *lastButton;//记录上一个button
@property(nonatomic,retain)UIImageView *b3;//自定义按钮
@property(nonatomic,retain)NSTimer *timer;//时间计时器

@property(nonatomic,retain)UIView *myView;

@end

@implementation MyTabBar

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //删除现有的tabBar
    CGRect rect = self.tabBar.frame;
    //移除tabbarcontroller下边的长条
    [self.tabBar removeFromSuperview];
    //[self.tabBar setHidden:YES];
    
    //添加自定义tabBar
    self.myView = [[BaseView alloc] init];
    self.myView.frame = rect;

    self.myView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myView];
    
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 0.5)];
    aView.backgroundColor = [UIColor colorWithRed:50 / 255.0 green:50 / 255.0 blue:50 / 255.0 alpha:1.0];
    [self.myView addSubview:aView];
    
    //添加按钮1
    UIButton *b1 = [[UIButton alloc] init];
    b1.frame = CGRectMake( 20 * XWIDTH, 5, 40 * XWIDTH, 40 * XWIDTH);
    [b1 setImage:[UIImage imageNamed:@"Recommend"] forState:0];

    b1.tag = 1001;
    [b1 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    b1.selected = YES;
    [self.myView addSubview:b1];
    
//    b1.backgroundColor = [UIColor blackColor];
    //添加按钮2
    UIButton *b2 = [[UIButton alloc] init];
    b2.frame = CGRectMake( 94 * XWIDTH, 5, 40 * XWIDTH, 40 * XWIDTH);
    [b2 setImage:[UIImage imageNamed:@"Destination"] forState:0];
    
    b2.tag = 1002;
    [b2 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.myView addSubview:b2];
//    b2.backgroundColor = [UIColor redColor];
    
    //添加按钮3
    UIButton *b3 = [[UIButton alloc] init];
    b3.frame = CGRectMake(170 * XWIDTH, 5, 40 * XWIDTH, 40 * XWIDTH);
    [b3 setImage:[UIImage imageNamed:@"Weather"]forState:0];
   
    b3.tag = 1003;
    [b3 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.myView addSubview:b3];
    
//    b3.backgroundColor = [UIColor blueColor];
    
    
    //添加按钮4
    UIButton *b4 = [[UIButton alloc] init];
    b4.frame = CGRectMake(243 * XWIDTH, 5, 40 * XWIDTH, 40 * XWIDTH);
    [b4 setImage:[UIImage imageNamed:@"Other"] forState:0];
    
    b4.tag = 1004;
    [b4 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.myView addSubview:b4];
    
//    b4.backgroundColor = [UIColor greenColor];

    
    //添加按钮5
    UIButton *b5 = [[UIButton alloc] init];
    b5.frame = CGRectMake(315 * XWIDTH, 5, 40 * XWIDTH, 40 * XWIDTH);
    [b5 setImage:[UIImage imageNamed:@"My"] forState:0];
    
    b5.tag = 1005;
    [b5 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.myView addSubview:b5];
    
//    b5.backgroundColor = [UIColor greenColor];
    

    //将上一个按钮赋值为第一个按钮
    self.lastButton = b1;
}

//1,2,3,4,5按钮点击事件
-(void)buttonAction:(UIButton *)button
{
    self.lastButton.selected = NO;
    button.selected = YES;
    self.lastButton = button;
    self.selectedIndex = button.tag - 1001;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
